package com.ruoyi.point.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.point.pojo.ConfigurationInformation;
import com.ruoyi.point.service.IConfigurationInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 组态管理Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/system/information")
public class ConfigurationInformationController extends BaseController
{
    @Autowired
    private IConfigurationInformationService configurationInformationService;

    /**
     * 查询组态管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConfigurationInformation configurationInformation)
    {
        startPage();
        List<ConfigurationInformation> list = configurationInformationService.selectConfigurationInformationList(configurationInformation);
        return getDataTable(list);
    }

    /**
     * 导出组态管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:information:export')")
    @Log(title = "组态管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConfigurationInformation configurationInformation)
    {
        List<ConfigurationInformation> list = configurationInformationService.selectConfigurationInformationList(configurationInformation);
        ExcelUtil<ConfigurationInformation> util = new ExcelUtil<ConfigurationInformation>(ConfigurationInformation.class);
        util.exportExcel(response, list, "组态管理数据");
    }

    /**
     * 获取组态管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:information:query')")
    @GetMapping(value = "/{configurationId}")
    public AjaxResult getInfo(@PathVariable("configurationId") Long configurationId)
    {
        return success(configurationInformationService.selectConfigurationInformationByConfigurationId(configurationId));
    }

    /**
     * 新增组态管理
     */
    @PreAuthorize("@ss.hasPermi('system:information:add')")
    @Log(title = "组态管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConfigurationInformation configurationInformation)
    {
        return toAjax(configurationInformationService.insertConfigurationInformation(configurationInformation));
    }

    /**
     * 修改组态管理
     */
    @PreAuthorize("@ss.hasPermi('system:information:edit')")
    @Log(title = "组态管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConfigurationInformation configurationInformation)
    {
        return toAjax(configurationInformationService.updateConfigurationInformation(configurationInformation));
    }

    /**
     * 删除组态管理
     */
    @PreAuthorize("@ss.hasPermi('system:information:remove')")
    @Log(title = "组态管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{configurationIds}")
    public AjaxResult remove(@PathVariable Long[] configurationIds)
    {
        return toAjax(configurationInformationService.deleteConfigurationInformationByConfigurationIds(configurationIds));
    }
}
